<template>
  <div class="hello">
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户" prop="name">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input v-model="ruleForm.password" ></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="login('ruleForm')">登录</el-button>
  </el-form-item>
   </el-form>
  </div>
</template>

<script>
export default {
  data () {
    return {
         ruleForm: {
          name: '',
          password:''
         },
         rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 1, max: 10, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
         }
    }
  },
  methods: {
      testlogin(){
        this.axios.get("/user").then(res=>{
         
        })
      },
       login(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.axios.post("/login",this.ruleForm).then(res=>{
                if(res.data.code == 200){
                    // redata = {"code":200,"token":token,'name':user['name'],'id':user['id'],'mpstatus':user['mpstatus'],'roleid':user['roleid'],'menulist':menulist}
                    //返回的数据存储
                    localStorage.setItem('adminid',res.data.id)
                    localStorage.setItem('menulist',JSON.stringify(res.data.menulist))
                    localStorage.setItem("mpstatus",res.data.mpstatus)
                    localStorage.setItem("token",res.data.token)
                    localStorage.setItem("pomitionlist",JSON.stringify(res.data.pomitionlist))
                    //判断mpstatus状态，如果为1跳转到修改密码页面，其他跳转到首页
                    if(res.data.mpstatus == 1){
                        //修改密码页面成功后更新localStorage.setItem("mpstatus",res.data.mpstatus)
                        window.location.href="http://localhost:8080/#/modifypwd"
                    }
                }else{
                    alert(res.data.mes)
                }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
  },
  mounted() {
    this.testlogin()
  },
}
</script>


<style scoped>

</style>
